package com.xzakota.minesweeper.ui.frame;

import com.xzakota.minesweeper.ui.IWindow;

import javax.swing.*;
import java.awt.event.WindowEvent;

/**
 * 抽象自定义界面
 *
 * @author Xzakota
 */
public abstract class AbstractBaseFrame extends JFrame implements IWindow {
    public AbstractBaseFrame() {
        this("BaseFrame");
    }

    public AbstractBaseFrame(String title) {
        super(title);

        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void showWindow() {
        setVisible(true);
    }

    @Override
    public void hideWindow() {
        setVisible(false);
    }

    @Override
    public void closingWindow() {
        dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
    }

    @Override
    public void closeWindow() {
        dispose();
    }

    @Override
    public boolean isShowing() {
        return isVisible();
    }

    protected void updateUI() {
        pack();
        setLocationRelativeTo(null);
    }

    public void showMessageDialog(String title, String message) {
        JOptionPane.showMessageDialog(null, message, title, JOptionPane.INFORMATION_MESSAGE);
    }

    public void showMessageDialog(String title, String message, int messageType) {
        JOptionPane.showMessageDialog(null, message, title, messageType);
    }
}
